//import "md5.js";
var DemoComponent = React.createClass({
    getInitialState: function () {
        return {data: [],host:"http://app.uyu.com:3001"};
    },
    componentDidMount: function () {
    },
    loginButton:function(){
        var url = this.state.host + "/user/login";
        var refs = this.refs;
        var login_name = React.findDOMNode(refs.login_name).value;
        var passWord = React.findDOMNode(refs.password).value;
        var data = new FormData();
        data.append("login_name",login_name);
        data.append("password",hex_md5(passWord));
        var self=this;
        fetch(url,{
            method: "POST",
            body:data
        }).then(function (response) {
            return response.json();
        }).then(function (json) {
            if (json.code == 0) {
                window.open("./applist.html?tk=" +json.data.token,"_self");
            }else{
                alert(json.message);
            }
        });
    },

    // 使用 render 方法自动渲染 DOM
    render: function () {
        var self = this;
        var styles = {
            loginPage: {position: "absolute", top: "50%", left: "50%", marginLeft: "-100px", marginTop: "-70px", width: "200px", height: "140px"},
            loginBg:{position:'absolute', width:document.body.clientWidth, height:document.body.clientHeight, background:'#1ca4d6', zIndex:3, overflow:'hidden'}
        };
        return (
            <div style={styles.loginBg}>
                <div className="component-container">
                    <div style={styles.loginPage}>
                        <div className="login-title">管理员登陆</div>
                        <form method="post" encType="form-data">
                            <p className="login-user login-username"><input ref="login_name" type="text" name="login_name" placeholder="用户名"/></p>
                            <p className="login-user login-password"><input ref="password" type="password" name="password" placeholder="密码"/></p>
                            <p className="login-user"><input className="login-button" type="button" name="button" value="登录" onClick={this.loginButton.bind(null)}/></p>
                        </form>
                    </div>
                </div>
            </div>
        )
    }
});

// 将组件插入到网页中指定的位置
React.render(<DemoComponent />, document.getElementById('demo'));
